title: New Line Added in file write when inserting text
body: <p>I've tried several ways to append a string to a line being written to a file when reading from another file (as well as in place using fileinput). I'm definitely missing something but trying different approaches for a few hours has not fixed the problem. </p>
  
  <p>The latest approach is below, which still results in the imagelist being on a new line after the datarow where the goal is to output them to a single line.</p>
  
  <pre><code>for datarow in oldfile:        
      rowcols     = datarow.split('|')    
      imagelist   = []
      image_seed  = rowcols[headers.index('Group ID')]+'_'+rowcols[headers.index('Case ID')]+'_'+rowcols[headers.index('Contact ID')]
  
      if isfirstrow:
          newfile.write(headerrow)
          isfirstrow = False
      else:
          for imagename in imagefiles:
              if image_seed in imagename:
                  imagelist.append(os.path.basename(imagename))
          if len(imagelist) &gt; 0:
              imagelist.insert(0, datarow)
              newfile.write('|'.join(imagelist)+'\n')
          else: newfile.write(datarow)
  </code></pre>
  
  <p>Thanks in advance for you input!</p>