Write to a file, falling back to stdout.