in reply to Cookie not being set

your call

print header(-cookie=>$ucookie, -location=>$new_url);

is wrong, try this
print redirect( -uri=>$new_url, -cookie=>[$ucookie] );
If you want to fullfill that with header() you must also supply a HTTP-Status code, eg. 302 Moved or 303 See Other.

Have a nice day
All decision is left to your taste