in reply to if ( -d ) question

It is always a wise idea to create a fully-qualified file name for use in all such tests.   There are portable CPAN modules that can help you with doing that.   When you are testing to see if a thing exists, it is critical that you are precisely sure what (Perl thinks...) you are actually looking for.   It is terribly easy to destroy a priceless Ming vase...