The _dup() function is useful for redirecting stdout to a file written on the disk.
_dup()
stdout
Additional information about redirecting stdout