Yes, using localhost is the problem. Your KML file has to be publicly accessible to be used with the JS API. This is documented in the Working with KML Layers topic:
Originally Posted by derickson48
The reason behind this requirement is that the KMLLayer class relies on a service hosted on ArcGIS.com to convert the actual KML to JSON. You can see this happening with firebug or chrome dev tools...here's the URL that's genereated from the simple KML layer sample:
To add a KML file(.kml or .kmz) to a map, the KML must be available via a publicly accessible URL. Locally hosted or KML files inside a firewall are not supported.