Are you sure the $element is the full path to the directory you want to open - or else you are executing this script from the correct place s.t. $element is a relative directory from your cwd? You can confirm this with:
die "no dir named $element\n" unless ( -d $element);
just before your opendir stmt.