Derivative of $\sec^{-1}x$ and integral of $\frac{1}{x\sqrt{x^2-1}}$

The reason you didn't get the absolute value when you differentiated is that $$\newcommand{\sgn}{\text{sgn}} \tan(\theta)=\tan(\sec^{-1}x)=\sgn(x)\sqrt{x^2-1} $$ so the derivative is $$\frac{1}{\sgn(x)x\sqrt{x^2-1}}=\frac{1}{|x|\sqrt{x^2-1}} $$

Sometimes the principal range of $\sec^{-1}x$ is assumed to be $[0,\frac \pi2)\cup [\pi, \frac{3\pi}{2})$. This convention is popular when doing integration with $\sec^{-1}x$ substitution and avoids the issue with the absolute value. Under that convention, $$\int \frac{1}{x\sqrt{x^2-1}}=\sec^{-1}(x)+C $$

If you don't like redefining the range of $\sec^{-1}(x)$, then $$\int \frac{1}{x\sqrt{x^2-1}}=\sec^{-1}(|x|)+C $$ as @YvesDaoust wrote.