The reason mentioned in the documentation IO Open Mode
"b" - Binary file mode. Suppresses EOL <-> CRLF conversion on Windows and sets external encoding to ASCII-8BIT unless explicitly specified.
Thus you need to use 'wb'
instead of 'w'
to resolve your issue.
You can write code something like below :
content = [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x0D, 0x0A] # "Hello\r\n"
f = File.new("PATH", "wb")
content.each {|b| f.write(b.chr)}
f.close