in reply to Oh ye who are in the gall of perlness...what maketh me mistaketh :)

My first response is that you should simply be doing test($sandbox);, not test("$sandbox");. That isn't going to make a difference here, but my $directory = "@_"; makes me cringe. Doing my ($directory) = @_; would seem to be more standard.

Along the same lines, doing if ("$pwd" eq "$directory") { also does too much string interpolation. Just do if ($pwd eq $directory) {.

Now the problem you're having is that you're saying if the two variables are string-wise equivalent, complain that you're not in the same directory, otherwise say that you are. You probably wanted one of the following:
unless ($pwd eq $directory) {
or
if ($pwd ne $directory) {

That should fix your problem.