Change file.write to file.puts to get implicit newline