Ok, how did you use this function you created? The tutorial mentions running in a shell script. I just tried putting this into a script called test.bash:
echo "Changed directory to /"
If you execute that script from a directory other than root, it should tell you the working directory is /, but when it quits, you'll be in the same directory you started the script from.
This is why: The '#!/bin/bash' at the top says to create a new bash shell and execute the commands within that new shell. This new shell is another process, and not at all related to the shell you started the script from. It's similar to having two terminals open at the same time.