code: def create_textfile_with_contents(filename, contents, encoding='utf-8'):
      
      ensure_directory_exists(os.path.dirname(filename))
      if os.path.exists(filename):
          os.remove(filename)
      outstream = codecs.open(filename, "w", encoding)
      outstream.write(contents)
      if contents and not contents.endswith("\n"):
          outstream.write("\n")
      outstream.flush()
      outstream.close()
      assert os.path.exists(filename), "ENSURE file exists: %s" % filename
docs: Creates a textual file with the provided contents in the workdir.
      Overwrites an existing file.