Check return value on fwrite