Fixed potential unclosed file handle.
Added handling for when gmtime() returns a NULL pointer.
Improved fopen() error message.
Removed redundant error check.
Corrected formatting.