<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _export_work_errors(self, work, output_file):
 """Saves errors for given work pieces into file. Args: work: instance of either AttackWorkPieces or DefenseWorkPieces output_file: name of the output file """

    errors = set()
    for v in itervalues(work.work):
      if v['is_completed'] and v['error'] is not None:
        errors.add(v['error'])
    with open(output_file, 'w') as f:
      for e in sorted(errors):
        f.write(e)
        f.write('\n')