Random addition - I had a similar problem (getting bad hostname when executing within apache but not from command line). Turns out I had multiple httpd instances running as different users (root, nobody). When I straightened that out and restarted everything cleanly (no root instances of http), all worked fine.
in reply to Re: LWP::UserAgent connection problem as CGI
in thread LWP::UserAgent connection problem as CGI