I'm not sure why you have the single backslash in your directory name, but if you are using Windows then you need to escape the slash, (e.g.
my $dir = "\\TestDir";).
Either way, don't use backslashes. This way you don't have to worry about escaping them. Here's an example (I'm assuming your using windows because of your $dir definition):
my $dir = "c:/docume~1/chris/TestDir";
if (-d $dir) {
print "It Exists";
}
else {
print "Does Not Exist";
}
So, the first method you tried...the one w/out $dir in quotes should have worked. Try making $dir an absolute path, and use forward slashes. See if that makes a difference.
HTH,
Chris