On a note unrelated to the redirection of the output, is there any reason why you want to be using $$ as a parameter to this sub? $$ is global as the process id and you can access it from anywhere within the script. If you really want to be passing the pid of some other process, use a variable to indicate that, rather than changing $$.