in reply to printing to new output files within a loop

What amw1, Sandy, and Old_Gray_Bear say looks good; but there is also File::Temp.

Be Well,
rir