I will have to look at this more, but SET-COOKIE will only set the cookie on the browser when you are returning data to the browser. If you just use "SET-COOKIE" in HTTP_REQUEST it will add the cookie to the request going to the server, but it will not be there when the response goes back to the client.
So you either need to do a redirect, or save the value of the cookie in a variable and then do the SET-COOKIE in HTTP_RESPONSE.
Without reviewing the iRule completely I personally would save the Cookie value as a variable and set it in the HTTP_RESPONSE section to avoid sending what on my quick initial analysis appears to be be an unnecessary redirect.