Are you reading the test.dat
file using a text editor? You're correct in that the program should be writing the string to the file as binary, but if you're opening the file in a text editor, the text editor is probably interpreting the binary as ASCII characters, and displaying them as such.