Is that the actual code you're having trouble with? Because I don't see where you print the data to standard output. You'll have to print the data to both standard output and to the file if you want it to appear in both places...
If the file isn't being created, what user ID is your webserver executing as? Does that user have write access to your desktop? Also, do the error logs of your webserver say anything?
Also, why do you fetch the $URL twice? (once with LWP::UserAgent and once with HTML::TreeBuilder's new_from_url?)