Welcome to the Monastery. I took a look at your code and I notice that actually the complete version you posted is quite different from the smaller section you posted in your original question, so I'll try to respond to both.
As for your original question, my best guess as to why the cookie is not appearing comes from using the Unix command date to generate your query value. This string will have a newline on the end of it which may confuse your browser. One way to handle this, if that's really the value you want to use, is
my $value = `date`;
However, in the larger update you posted, the code appears to be working correctly. The code generates a cookie called "User-Name" and that is indeed what the browser shows.