Either use Array#each to iterate over your array and call IO#puts to write each element to the file (puts adds a record separator, typically a newline character):
File.open("test.txt", "w+") do |f|
a.each { |element| f.puts(element) }
end
Or pass the whole array to puts:
File.open("test.txt", "w+") do |f|
f.puts(a)
end
From the documentation:
If called with an array argument, writes each element on a new line.