All sorts of thoughts can happen to us out of the blue…
the fact that a though happened to one- does not mean per se there was any sin. Such can pop in -and there be not even a small sin.
And for mortal sin one needs not only grave matter, but full knowledge and deliberate (complete) consent…
(And some need some medical/professional assistance in this area…such as medication etc…as you note you struggle with OCD )
For the next few moments --try real hard NOT to think of Apple.
then scroll down.
What did you think of?
Even though your will was against it -you did not want to think of an apple.
The best thing to do with such thoughts is not to fight them directly --not fear that they will come…do not consent and simply and calmly turn to something else…(or it may be best to keep doing the good thing one is doing…like they come out of the blue when your at work …keep working …etc)
Ignore such unwanted thoughts like one would ignore a hissing goose or a barking dog. One does not stop to argue with a hissing goose or a barking dog does one? No one keeps on walking…and at most laughs at them…
(as noted above the image there comes from a Carthusian Monk from centuries ago)
As to confession -one is only obliged to confess mortal sins. Venial sins can be confessed.
Things that are not sinful (like unwanted thoughts that pop in and we do not consent --indeed we do not want them at all!) – are not even matter for confession.