Slight fix on number of calls to fwrite