www.yourhost.com is not the same as yourhost.com, so when your links don't match, this isn't working.
You can just take out the www. if you know that this will always lead to a valid URI.
(Also, your use of .each is almost redundant, as jQuery is already knowledgeable about element sets; however, you need it for this.href. Just something to be aware of.)
$("a").filter(function() { return this.hostname && this.hostname.replace(/^www\./, '') !== location.hostname.replace(/^www\./, ''); }).each(function() { $(this).attr({ target: "_blank", title: "Visit " + this.href + " (click to open in a new window)" }); });