Notice, your result is correct because adding or subtracting a constant will make no difference in the result. This can also be obtained using integration by parts
let $$I=\int \sqrt{x^2+a^2}\ dx\tag 1$$
$$I=\int \underbrace{\sqrt{x^2+a^2}}_{I}\cdot \underbrace{1}_{II}\ dx$$
using integration by parts
$$I=\sqrt{x^2+a^2}\int \ dx-\int\left(\frac{d}{dx}(\sqrt{x^2+a^2})\cdot \int 1\ dx\right)\ dx$$
$$I=x\sqrt{x^2+a^2}-\int\left(\frac{2x}{2\sqrt{x^2+a^2}}\cdot x\right)\ dx$$
$$I=x\sqrt{x^2+a^2}-\int\left(\frac{x^2}{\sqrt{x^2+a^2}}\right)\ dx$$
$$I=x\sqrt{x^2+a^2}-\int\frac{(x^2+a^2)-a^2}{\sqrt{x^2+a^2}}\ dx$$
$$I=x\sqrt{x^2+a^2}-\int \sqrt{x^2+a^2}\ dx+a^2\int\frac{1}{\sqrt{x^2+a^2}}\ dx$$
from (1)
$$I=x\sqrt{x^2+a^2}-I+a^2\int\frac{1}{\sqrt{x^2+a^2}}\ dx$$
$$I=\frac{1}{2}\left(x\sqrt{x^2+a^2}+a^2\int\frac{1}{\sqrt{x^2+a^2}}\ dx\right)\tag 2$$
Now, let $x=a\tan \theta\implies dx=a\sec^2\theta\ d\theta$ $$ \int\frac{1}{\sqrt{x^2+a^2}}\ dx= \int\frac{1}{\sqrt{a^2\tan^2\theta+a^2}}(a\sec^2\theta \ d\theta)$$
$$=\int \sec\theta\ d\theta=\ln|\sec\theta +\tan\theta|$$
$$=\ln\left|\tan\theta+\sqrt{\tan^2\theta+1}\right|=\ln\left|x+\sqrt{x^2+a^2}\right|+c$$
setting the value in (2), we get
$$I=\frac{1}{2}\left(x\sqrt{x^2+a^2}+a^2\ln\left|x+\sqrt{x^2+a^2}\right|\right)$$