I could see what part of the exam paper another student seemed to be focusing on, now I'm worried I was cheating
OCD or similar, if formally diagnosed, could be legally considered a disability. Your school would then be obligated to accommodate your needs in an instructional setting.

Taking examinations in a separate room is a very common form of accommodation for students with mental disabilities. Whoever it is in your institution that deals with students with disabilities will be very familiar with this measure. Schools like it because it's easy and cheap to accomplish.

Given how upsetting this experience seems to be for you, and that it sounds like it wasn't a one-off thing, I'd really advise you to get together with your Office of Disability Services or whatever it's called and figure out a way that you can take exams without having to struggle with these challenges.