Try adding -xv to the end of your first line - the /bin/bash one.
It will run the shell in debug(ish) mode but what is useful is it shows you what the variables are set to. If /opt/XX1/XX1 doesn't exist then your last line effectively becoms just 'cd' - which *will* return you to your $HOME.
When you run a script, it executes in a subshell. That subshell has its own environment space, so things like $PWD (or any set variable) will be lost. To paraphrase: "What happens in a subshell stays in a subshell."
Therefore, you canot use a script to change the current working directory of your login shell. You could define an alias, or a function, which would run in the current shell. But the script can't do it.