If you look at the help page for If and you click on Details then you find
If[condition,t,f] is left unevaluated if condition evaluates to neither True nor False.
Mathematica recognized your If and then evaluated your condition to try to determine whether it was True or False. To do that it evaluated x and the local variable ww, to do that it determined that ww had been assigned the value ArcTan[x]. You have not assigned a value to x and so the value of x<ArcTan[x] is just x<ArcTan[x]. That is neither True nor False and thus it evaluates nothing further and the result is If[x<ArcTan[x], ww, x]
Yes, Piecewise is more suitable here because it is explicitly designed for symbolic computations. If is primarily for flow control when programming, but it tends to work with many symbolic math functions too.