RangesIO#write corrupts output if passed and UTF8 string

RangesIO#write has a bug which corrupts the output file if the encoding is UTF-8, due to differences between the string size as reported by String#length and the actual number of bytes written (as File#tell would report). This patch fixes de issue.