Replace FILE* functions with their file descriptor equivalents

FILE* functions are limited by FOPEN_MAX. On FreeBSD 10.1, this is
SHRT_MAX (32767). Unfortunately, on a busy server with lots of memory,
this limit could easily be hit. Note that open sockets and files opened
by open system call variants also count towards this limit. This
replacement is actually better for logging as we directly write to
file instead of fwrite followed by fflush.