When you use scanf, it translates a human readable form (%d) into something the computer uses directly (int). You then write out the computer-readable form into a file. Now, when you view the file, you are NOT using the inverse computer-to-human-readable form but something much lower-level. This will give you something that looks wrong.
You are writing out the entire x.data even though you may have read partial data into it (say, reading a string that's length 10). The remainder of the x.data is "uninitialized" and contains whatever was left in memory when main() was called.