Hi Johan and welcome to the forum!
That’s a weird behaviour of checkmk and I don’t know if they made this intentionally. The culprit is the exit 1 in the bad case.
The thing is: If the local check is located in /usr/lib/check_mk_agent/local/ and runs synchronously every minute, then the returncode of the local check doesn’t matter. It is ignored.
BUT if the file is located in one of the number subdirectories (like /usr/lib/check_mk_agent/local/300) then the check is run in background (every five minutes) and if then the returncode is != 0, then its output is simply discarded.
So just change exit 1 to exit 0 in all cases.
Except maybe for some fatal error if the script cannot run at all, like wrong credentials or access rights or something like that. But be aware that it will then behave differently if run every minute vs. every N minutes.