openHAB is already running as user openhab. This part is redundant at best but if you’ve never run sudo as the openhab user before, the first time it requires you to acknowledge a message before it will execute a command.
Forget about all the sudo stuff and just run the script directly. You may need to use the full path and you may need to install any libraries that the script depends upon for user openhab or globally.
under which conditions ? What is the user that is currently being logged in ?
then its being executed as user openhab.
That means when its being executed from within openhab it also should work as all processes run with openhab user permissions.
In case it does not work use the executeCommandLine version that stores returned values in a variable and write that variable as debug output to openhab.log file it should give more information about the root cause then.