in reply to files stored in an array

Your code opens up a new output file for every line in all of the input files. Is this what you're intending?

A couple of general comments: