You are tasked with proving that $\tan(\frac x 2) = \dfrac {\sin(x)}{1+\cos(x)}$. If we suppose that this is not an impossible task (i.e. that the identity is correct) then neither $\tan(\frac x 2) =\pm\dfrac {\sin(x)}{1+\cos(x)}$ nor $\tan(\frac x 2) =\left|\dfrac {\sin(x)}{1+\cos(x)}\right|$ are satisfactory places to end up. The first version, which you arrived at, is not exactly incorrect, but rather incomplete, because it doesn't say which sign applies. The second version, from the answer book, is incorrect when $\tan(\frac x2)<0$.
In general, $a=\pm b$ gives you the same information as $|a|=|b|$. However, in this case we can determine which sign applies. Your work essentially shows that $\left|\tan(\frac x 2)\right| =\left|\dfrac {\sin(x)}{1+\cos(x)}\right|$. But note that $1+\cos(x)\geq 0$ so it does not affect the sign, and $\sin(x)$ always has the same sign as $\tan(x/2)$. To see that the last point is true, it is enough to work in the interval $(-\pi,\pi)$ by periodicity. Both $\tan(x/2)$ and $\sin(x)$ are positive when $x$ is in $(0,\pi)$, and both are negative when $x$ is in $(-\pi,0)$.
That said, I agree with lab bhattacharjee that avoiding methods that require later working out signs is a good idea.
Here is a side issue, which in the original version of my answer was all I posted:
$\sqrt{x^2}=|x|$ is an identiy for real numbers $x$. The reason is that for a nonegative real number $a$, $\sqrt{a}$ is defined to be the unique nonnegative squareroot of $a$. Since $|x|^2=x^2$, it follows that $|x|$ is the nonnegative real number whose square is $x^2$.
Therefore $\sqrt{\left(\dfrac{\sin x}{1-\cos x}\right)^2}=\left|\dfrac{\sin x}{1-\cos x}\right|$.