<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_report(self, session, filename):
 """ Writes the report in JSON format to the given file """

        if not self.__report:
            session.write_line("No report to write down")
            return

        try:
            with open(filename, "w+") as out_file:
                out_file.write(self.to_json(self.__report))
        except IOError as ex:
            session.write_line("Error writing to file: {0}", ex)