I've been looking for the exact text, or at least a link to the Chatam Sofer bringing down the Ari on the topic of soulmates in Shu”t Chatam Sofer 7:34. I've seen it quoted in several articles, but have been unable to find the text online or on Sefaria.
Teshuvos Chasam Sofer Volume 7 is a collection of (until recently) unpublished responsa from the Chasam Sofer. It's under copyright from the Machon Chasam Sofer, so you won't find it on Sefaria.
Luckily for you, it's on Otzar Hachochma, and it's within the first 150 pages, so it's available for free viewing. Here's a link to Chasam Sofer 7:34. The paragraph you want starts with ונראה.
I don't have time right now to transcribe the teshuva. What he basically says is zivug rishon is one's initial, predestined mate, and through a person's actions they can either deserve a better mate or a worse one, which is their zivug sheni. This fits nicely with the gemarra's statement that a person's mate is לפי מעשיו.
Note that when citing this explanation, he writes that he thinks it's from the Arizal. However, the Arizal doesn't say this. In his Shaar HaGilgulim Introduction 20 and Sefer HaGilgulim Chapter 13, he says instead that zivug sheni has to do with gilgulim, reincarnation.