docgen: Don't use stdin and stdout

The encoding on stdin and stdout are usually ascii and may cause problems
with writing unicode to it. Instead of this we open the file directly
and avoid dealing with annoying unicode encode/decode errors.