Fix incorrect checks for the fwrite() return value

! fwrite() could trigger false-positives as it is possible for it to return 0
instead of boolean FALSE. (issue #2822)

Also removed an unnecessary log level check that caused an extra space to be inserted
for the INFO level. (proposed in PR #2821)