Move file.Write into the loop.