Close file descriptors

Closes file descriptors and restores STDOUT_FILENO
after stdout redirection.