This script has more problems than just not working. You don't
use strict (which is one reason I'm not going to look any closer at your script), and you don't check to see whether or not any of your calls to
open succeed or fail (also check the call to
close on the pipe open). That's just what I see in addition to other's comments.