Complex substitutions is a common source of error in real integration. It often leads to wrong results if you don't know what you are doing and to do the derivation you have attempted to do rigorously you cannot get away from the theory of complex integration and the complex logarithm.
However the beauty of indefinite integration is that you can use whatever method you like (rigorous or not) to get the answer as long as you check in the end by differentiating the result and show that you recover the integrand.
In your case a naive derivation can indeed give the correct answer. If we naively use $\int \frac{{\rm d}t}{t+a} = \log(t+a)$ then we end up with
$$\int \frac{x^2}{(x^2+1)^2}{\rm d}x = -\frac{i}{4}\left[\log\left(\frac{t-1}{t+1}\right) - \frac{2t}{t^2-1} \right]_{t=x/i} + C$$
Now using a known connection between the logarithm and the arctan-function $\arctan(x) = \frac{1}{2i}\log\left(\frac{x-i}{x+i}\right)$ we end up with the manifestly real result
$$\int \frac{x^2}{(x^2+1)^2}{\rm d}x = \frac{\arctan(x)}{2} - \frac{x}{2(1+x^2)} + C$$
For the crucial step to make it a valid proof: differentiating the right hand side we find that we do indeed recover the integrand showing that the answer is correct (even through the derivation was a bit sketchy).