Why is this macro running in Safari

I set it up to create an auto-save function in LibreOffice, and it works fine. But it also prompts me to save a page in Safari every three minutes, despite my telling the macro to only work in the LibreOffice window. What did I do wrong?

Where do you tell it to work only in the LibreOffice window? I'd recommend to put it into a Macro Group which is "Available in these applications - LibreOffice". The "Triggered..." line of your macro's window will then change to "Triggered by any of the following (when LibreOffice is at front):"

edit: I now found that you send the keycommand to LibreOffice only, OK. I wonder if that makes much sense anyway because it will try to do so always, no matter if LibreOffice is used or not.

Your macro looks fine. The action, configured to send the Command-S to the target application, should work, but applications do not always expect to receive keys in the background.

That said, that works fine if used with BBEdit so it may be an issue with LibreOffice not accepting keys will in the background.