Oh bloody hell, I knew it'd be something stupid like that. I think I'd best go to sleep, I've rewritten it and it's working now. Thanks guys.
[edit:] I just wrote it how I have been writing all my other binary files, but those have had to be read back in and not viewed in notepad or anything so I just wasn't thinking.