<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _setup_output_file(self, output_filename, args, write_header=True):
 """Open and prepare output file."""

        # write command line into outputFile
        # (without environment variables, they are documented by benchexec)
        try:
            output_file = open(output_filename, 'w') # override existing file
        except IOError as e:
            sys.exit(e)

        if write_header:
            output_file.write(' '.join(map(util.escape_string_shell, self._build_cmdline(args)))
                              + '\n\n\n' + '-' * 80 + '\n\n\n')
            output_file.flush()

        return output_file