The code in detect.sh passes HDF5_DIR as the "GUESS" (7th) argument of find_lib and eventually that argument is prepended to the list of "usual" directories in bash_utils.sh
local DIRS="$GUESS /usr /usr/local /usr/local/packages /usr/local/apps /opt /opt/local $HOME c:/packages"
This seems wrong. If a HDF5_DIR is given then the configure stage should fail if HDF5 is not found there. Otherwise the system would unexpectedly pick eg a system hdf5 instead of one from a module if the module was updated and its path changed.