in reply to LWP::UserAgent and sending the HTTP_REFERER

The version of LWP::UserAgent that I have does not have a method called "header", I imagine that yours is the same; hence the error.

Looking at the docs it seems like the following may work for you:
$ua->default_header( 'Referer' => $referer ) if defined $referer;