Added Error Checking for dup2() and close()