Rather than saving the actual lines to be printed to stdout or the file, save only the data strings themselves. Then upon printing, specify a delimiter (or use a default) to print the data. The default for printing to stdout should be a tab and the default for print to a file should be a comma.