Write to a file line by line - Loop