I think when you ran the script the first time you were prompted to accept the remote host’s fingerprint of the host’s key.
Running the script by with openhab user privileges the first time should prompt for it as well.
To get around it either run the command as user openhab to accept it and let it store in .ssh directory in user openhab home directory or use a slightly modified version:
Other problem could be that the sudo command returns something but as it is being run at the other end of ssh endpoint it is being executed with same privileges that you already tested so that should be fine.
In case the above does not work try to create debug output by redirecting stderr and stdout of the ssh command to a file.
Logging interactively I could see the prompt for saving ssh keys, that were the issue here.
After one time ssh login now all executes fine.
The other script that was working dine was very old one and I must have done that previously and forgot.