What you describe as what needs to happen does not justify the complexity of what you want to do, unless the second program is running all the time anyway.
If you can get the process ID of the second program (which, as I said, has to be running already), a signal can be sent to it using shell's "kill" command. Then, the program that receives that signal (using the "trap" command) can take the steps needed to read the file that was found, write its content to another file, and delete it.
If you really want to use sockets, I think a C program (or maybe perl? does perl have a sockets library?) might be the ticket.
Otherwise, in the shell it's as simple as
while true
do
if [ -f $filename ]
then
kill -$whatever $pid
fi
sleep $number_of_seconds
done