Char conversion when using puts to write file lint by line

I’m trying to create a script to generate several win32 registry entries
in a .reg file, using a template. The idea is that I have a registry
entry in the template file with tokens to be replaced by values I
determine.
I’m getting a weir behavior when trying to do the following:

def createFromTemplate (src, template,filename)
raise "Template file not found "+template if !File.file?(template)
f = File.open(template)
nf = File.new(filename,‘w+’)
f.each{|line|
nf.write line
}
end

I would expect this code to copy all the lines from the template file to
the result file. Instead I’m getting the following:

Template file:
Windows Registry Editor Version 5.00

[HKEY_USERS\S-1-5-21-216280869-1618010840-3877511435-1006\Software\SimonTatham\PuTTY\Sessions]

[HKEY_USERS\S-1-5-21-216280869-1618010840-3877511435-1006\Software\SimonTatham\PuTTY\Sessions\PORTAL001%20CMPT%201%20-%20DB%20Tunnels]
“Present”=dword:00000001
“HostName”=“172.18.142.94”

Result file:
Windows Registry Editor Version 5.00
਍ഀഀ
[HKEY_USERS\S-1-5-21-216280869-1618010840-3877511435-1006\Software\SimonTatham\PuTTY\Sessions]
਍ഀഀ
[HKEY_USERS\S-1-5-21-216280869-1618010840-3877511435-1006\Software\SimonTatham\PuTTY\Sessions\PORTAL001%20CMPT%201%20-%20DB%20Tunnels]
਍∀倀爀攀猀攀渀琀∀㴀搀眀漀爀搀㨀       ㄀ഀഀ
“HostName”=“172.18.142.94”

Notice that the fn.puts call is adding unrecognized characters where in
the template file I would find CRLF.
If I do a File.copy, the file gets copyied without any char conversion.
Can someone help me determine what might be happening? I’m clueless.

I’m running Ruby 1.9 on Windows XP.

Regards