in reply to Text format array

I think your problem is that you are using chomp to remove the newline character, but when you use print you are effectively concatenating all the input lines into one long line. You need to add the newline back. Try this:
print "$line\n";