Fixed it - I was focussed on the function itself, but in fact, it was the session handling in PHP which was trying to read a cookie from the old domain, not recognizing it, and appending the sessionid to the <a href> tag - this happens before the UniqueHref function is even called.
So, another one to look out for...
thanks anyway, Vincent