Fixed file redirection by adding reset redirection function