On macOS the version on /usr/bin/bash is very old (bash 3 I think?), so many users install a newer version with homebrew which ends up in PATH, which /usr/bin/env looks at.
Protip: I start every bash script with the following two lines:
set -e makes the script exit if any command (that’s not part of things like if-statements) exits with a non-zero exit code
set -u makes the script exit when it tries to use undefined variables
set -o pipefail will make the exit code of the pipeline have the rightmost non-zero exit status of the pipeline, instead of always the rightmost command.