code: def write_to_file(path, contents, file_type='text'):
      
      FILE_TYPES = ('json', 'text', 'binary')
      if file_type not in FILE_TYPES:
          raise ScriptWorkerException("Unknown file_type {} not in {}!".format(file_type, FILE_TYPES))
      if file_type == 'json':
          contents = format_json(contents)
      if file_type == 'binary':
          with open(path, 'wb') as fh:
              fh.write(contents)
      else:
          with open(path, 'w') as fh:
              print(contents, file=fh, end="")
docs: Write ``contents`` to ``path`` with optional formatting.
  
      Small helper function to write ``contents`` to ``file`` with optional formatting.
  
      Args:
          path (str): the path to write to
          contents (str, object, or bytes): the contents to write to the file
          file_type (str, optional): the type of file. Currently accepts
              ``text`` or ``binary`` (contents are unchanged) or ``json`` (contents
              are formatted). Defaults to ``text``.
  
      Raises:
          ScriptWorkerException: with an unknown ``file_type``
          TypeError: if ``file_type`` is ``json`` and ``contents`` isn't JSON serializable