Check fwrite return code