UPDATE: Problem solved by adding InheritConsoleHandles mentioned in this fix. Thank you all guys for hints and help!
What can be the reason, that
script.pl > output.txt
creates empty file output.txt and
perl script.pl > output.txt
creates output.txt with data produced by script.pl?
This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2011, Larry Wall
Binary build 1402  provided by ActiveState http://www.ActiveSt
Built Oct 7 2011 15:19:36
on Windows 7.