Correctly iterate over input and output files in scala