> I want to read each line, process it, print that to another file, and then
> rename the output file.  

Something like this will do...

lines = File.readlines('in.txt')

File.open('out.txt', 'w+') do |fout|
  lines.each do |ln|
    ln.gsub!(...)
    fout.puts ln
  end
end

File.rename('out.txt', 'out.txt')