code: def write_to_file(self, output_file_path, intervals, template):
          
          msg = [template % (interval) for interval in intervals]
          if output_file_path is None:
              self.print_info(u"Intervals detected:")
              for line in msg:
                  self.print_generic(line)
          else:
              with io.open(output_file_path, "w", encoding="utf-8") as output_file:
                  output_file.write(u"\n".join(msg))
                  self.print_success(u"Created file '%s'" % output_file_path)
docs: Write intervals to file.
  
          :param output_file_path: path of the output file to be written;
                                   if ``None``, print to stdout
          :type  output_file_path: string (path)
          :param intervals: a list of tuples, each representing an interval
          :type  intervals: list of tuples