The order of operations in the script ought to be something like this:
- Create the CGI object
- Check the params
- If the params are good for the redirect, do that and exit
- Otherwise, print your header and the form and maybe some error message if the params were invalid
While you are there, you might also want to think about why you are using CGI twice, why you are using Getopt::Long and Fcntl and then apparently not referring to them, why you are not using strict and warnings, just how dangerous it is to shell out to a script located in /tmp and why you aren't running in taint mode.