file_name = "write_experiment" write_to = "{}.txt".format(file_name) textfile = open(write_to,"w+") heading ="=== MMF Test ===\n " content = "random content" more = "a bit more content" to_write = [heading, content, more] for item in to_write: print(item) for item in to_write: textfile.write(item) textfile.write("\n")