Bug fix (segfault): check filename against NULL in case we want
the output to go to stdout.