$pathis a directory so the expression -d "$path" is always true so @array will contain all directory entries including non-directories. You need to include the file name in the test for it to work correctly:
my @array = grep { -d "$path/$_" } readdir BIN;
my $new_ext = $ext_map{$ext} || $ext;
You don't define the variable $ext anywhere or give it a value.