I'm looking for such function g defined in some closed $X\subset\mathbb{R}$ such that $g'$ exists on $X$ and $g: X \rightarrow X$.
Some examples that I tried that does not work $g(x)=\frac{|x|^3+x^2+1}{x^2}$, for $X=\{x \in \mathbb{R}\ | |x|\geq a \ \}$ for some $a>0$ big enough.
Let $X=(-\infty,-1]\cup[1,\infty)$ and $g(x)=\frac12x+\operatorname{sgn}(x)$.