p. 464 Top of Calculus: Early Transcendentals (6 edn 2007) doesn't explain the discovery of this trick (in this question's title), that thus feels clairvoyant.
I understand, but ask not about, other less tricky methods to calculate $\int \sec x \,dx $.
As Micah suggested, use another method first, e.g. the frequently useful $t=\tan\frac{x}{2}$. Then $\int\sec x dx=\int\frac{2dt}{1-t^2}=\ln\frac{1+t}{1-t}+C$. But $$\frac{1+t}{1-t}=\frac{\cos\frac{x}{2}+\sin\frac{x}{2}}{\cos\frac{x}{2}-\sin\frac{x}{2}}=\frac{1+\sin x}{\cos x}.$$