One thing to check is the execution context when your SCCM runs the script. It might be running under a different user context or permissions setting compared to when you manually run it through Terminal. That could explain why it reports as installed but doesn't actually work.
As a workaround, have you considered breaking down the script steps or adding logging to pinpoint where it's getting stuck? It could help uncover if there's a specific step causing the hiccup.
Also, for backup notes during troubleshooting, I find using an online notepad really handy. It keeps everything organized across devices without relying on local files.