>  fin = File.open(ARGV[0],'r') rescue $stdin
>  fout = File.open(ARGV[1], 'w') rescue $stdout
>  fin.each_line do |line|
>    fout.print do_some_thing(line)
>  end

You should close an IO stream, when it is a file.

gegroet,
Erik V. - http://www.erikveen.dds.nl/