in reply to print to file not working

Then maybe you should turn on warnings!

You're reading from a file you've opened for writing.

open(CODE, "c:\\...\\killp.pl") doesn't execute that file, it opens it for reading. The whole of run_code attempts to replicate do or system.