You should instead have ( wrong differentiation )
$$
I'\left(a\right)=\int_{0}^{\pi}\frac{2a-2\cos\left(x\right)}{1-2a\cos\left(x\right)+a^2}\text{d}x
$$
Edit : You cannot evaluate in $1$ because the function is only diffentiable on $\left]1,+\infty\right[$ ( or $\left[0,1\right[ ). This subject was marked as duplicate but I dont think it answered why OP was wrong.
It's because you differentiated under the integral sign without proving you can. If you consider
$$
f\left(a,x\right)=\ln\left(1-2a\cos\left(x\right)+a^2\right)
$$
for $\left(a,x\right) \in \mathbb{R}^{*+} \times \left]0,\pi\right[$ then
$$
\frac{\partial f}{\partial a}\left(a,x\right)=\frac{2a-2\cos\left(x\right)}{1-2a\cos\left(x\right)+a^2}
$$
To show you can differentiate under the integral sign you need to find $\displaystyle \varphi \in \ell^{1}\left(\left]0,\pi\right[\right)$ such as
$$
\left|\frac{\partial f}{\partial a}\left(a,x\right)\right| \leq \varphi\left(x\right)
$$
You see that you cannot makes $a$ disappear unless you consider a compact set.
I dont have time I must go, however what is import to notice is that for $a=1$,
$$
1-2a\cos(x)+a^2=2-2\cos(x)
$$
And it can be equal to $0$ ( when $x=0$ and $0 \in \left[0, \pi\right]$ ! ) . Intuitively, you couldnt simplify it to $1$ when evaluating to $a=1$ because you cannot divide by $0$ and it could have taken the value $0$.
However, try to choose $a=2$ you'll find $k=2\pi$.