def write_file(outname, report_txt):
    """Write a generated report to a given file.

    Parameters
    ----------
    outname : string
        The name of the file to write/create.
    report_txt : string
        This is the generated report as a string.

    Returns
    -------
    out : string
        The name of the file written.

    """
    with open(outname, 'wt') as report_fh:
        try:
            report_fh.write(report_txt)
        except UnicodeEncodeError:
            report_fh.write(report_txt.encode('utf-8'))
    return outname
