6879689 : Fix warning about ignored return value when compiling with -O2
error: ignoring return value of 'size_t fwrite(const void*, size_t,
size_t, FILE*)', declared with attribute warn_unused_result
The fwrite library call is marked as requiring a warning if the return value is ignored. More recent gcc's can disable this via -Wno-unused-result but in general this warning will be issued and as we build with -Werror the warning becomes an error. So we need to avoid the warning.
We can use the return value in an assert that checks for success of the fwrite call.
We also switch the "size" and "nitems" parameters to fwrite to give a more meaningful size comparison.