change 'f << string + "\n"' to 'f.puts string'