I have a PR fixing this issue. If you want to try your script with this branch, it is here: https://github.com/tpm2-software/tpm2-tools/pull/2038