A Unix/Windows behavior difference:

  puts 1
  dbg = File.new "debug.txt","w"
  $stdout = dbg
  puts 2
  $stdout = STDOUT
  dbg.close
  puts 3

Desired output is "1\n3\n", with "2\n" going to debug.txt.  In Windows, 
output is "1\n", with "2\n3\n" going to debug.txt.

I notice that it works in Windows if $defout is substituted for $stdout. 
 ... but guess I don't quite understand the distinction.

  --Mark