in reply to Correct way to capture command output to a file in Perl.
See, in your first set of code it will display output on screen instead of writing into file. Second way is good to use.