Fixed fwrite + truncation bug