I cannot reproduce this with my Pro1-X. Not using Termux, though.
I'm running Debian 11 in a (rooted) chroot of LOS 20.0 and use ConnectBot as my terminal emulator. Your script works fine (with some trivial changes to match my environment).
As, also for you, the keyboard behaves normally in other apps, it seems to me that you are somehow triggering a bug in the terminal emulation of Termux.