How to prevent wp_insert_post from creating a new post every second?

Your plugin does no checking at all, such as “does the post already exists?”
Accordingly, it creates a post each time WordPress is called.

There is a system called WordPress heartbeat, which contacts the server every few seconds. Your plugin is called each time, and a post is created.

For reference, the Heartbeat doc.