[Short Answer]
You write $E [S_T]=S_0(1+r)^T $ but you actually compute the RHS as $X (1+r)^T$ in your numerical application.
[Long Answer]
The stock price is a martingale in an equivalent measure using the risk-free asset as numeraire i.e.
$$ E [S(T)] = (S_0 u) q + (S_0 d) (1-q) = S_0 (1 + r ) \Delta t $$
In that case, dividing each member by $S_0$ and re-arranging the terms yields
$$ q ( u - d ) + d = (1 + r ) \Delta t
$$
$$ q = \frac {(1 + r ) \Delta t - d}{u - d} $$
Doing the computations with your input data (assuming a tree period covers $\Delta t=1$)
$$ q = \frac {(1+0.05) - 0.9}{1.3-0.9} = 0.375 $$
Note that this expression for $q $ is exactly the one given in any textbook provided $u $ (resp. $d $) figures the upward (resp. downward) growth rate of the stock over a binomial tree period $\Delta t $, while $1 + r $ represents the growth rate of the risk free asset.
Note that sometimes continuous compounding is used, in which case:
$$ q = \frac {e^{r \Delta t} - d}{u - d} $$
Depending on the compounding convention you could also have
$$ q = \frac {(1 + r)^{ \Delta t} - d}{u - d} $$
of course.