capturing and saving the stdout to a file