$ x, f(x), f(f(x)), f(f(f(x), \ldots $ This list cannot go on forever, since $X$ is finite. So it must reach one that has appeared in the list earlier. Suppose $ f(f(f(f(f(f(f(x))))))), $ the seventh one, appeared earlier as the third one. Then $ f(f(f(x))) = f(f(f(f(f(f(f(x))))))). $ Since $f$ is one-to-one, we can cancel: $ x = f(f(f(f(x)))). $ But that doesn't mean $f\circ f\circ f\circ f$ is the identity. It only means that if you apply it to this one element, $x$, you get back $x$, NOT that if you apply it to every element $y$, you'll get back $y$.
So suppose $x$ re-appears in four steps $ x \mapsto f(x) \mapsto f(f(x)) \mapsto f(f(f(x))) \mapsto f(f(f(f(x)))) $ and some other element, $w$, re-appears in six steps: $ f(f(f(f(f(f(w)))))) = w. $ The smallest common multiple of $4$ and $6$ is $12$, so after $12$ steps, both $w$ and $x$ will re-appear simultaneously.
There are finitely many elements of $X$. Find the smallest common multiple of the numbers of steps it takes to get them to re-appear. After that many steps, the all re-appear simultaneously. So $f$ iterated that many times is the identity function on $X$.