Fix undefined behavior, don't pass NULL to fwrite