A subtle error that can occur here is to use single quotes instead of double. That also has the effect of rendering the newlines as \n. So
puts a.join("\n") # correct
is not the same as
puts a.join('\n') # incorrect
There is an excellent write up on why this is the case here.