How to prevent terminal from printing passwords from keychain?
Well,

PASSWORD=$(get_pw)


assigns the password to PASSWORD so it shouldn't be a surprise that

echo "$PASSWORD"


actually prints it on the Terminal.

The idea here is not to print it but to use it in another command to pass it on (as the example in the page you've linked to does). Even then the password is still visible in ps -E though.