It is unknown what kind of setup you really have but "Connection refused" is usually caused either by a firewall blocking connections (unlikely with localhost) or that simply no server is listening there.
Based on your use of Net::SMTP connection should work if you have a MTA setup on localhost port 465 (smtps), speaking directly TLS (i.e. no upgrade with STARTTLS) and with a valid certificate for "localhost". I have no idea if this is really the case but I would guess it is not.
To better debug the problem I would recommend to use the "Debug" switch for Net::SMTP. For SSL debugging run your code with "perl -MIO::Socket::SSL=debug4 program.pl".