Invariant subspaces of a linear operator that commutes with a projection I have an assignment problem, the statement is:

Let $V$ be a vector space and $P:V \to V$ be a projection. That is, a linear operator with $P^2=P.$ We set $U:= \operatorname{im} P$ and $W:= \ker P.$ Further suppose that $T:V\to V$ is a linear operator such that $TP = PT.$ Prove that $TU \subseteq U$ and $TW\subseteq W.$ 

Here is my attempt:
Suppose $u\in U:= \operatorname{im} P$ so $u= P(v)$ for some $v\in V.$ Then $Tu = TPv = PTv \in \operatorname{im} P := U$ so $TU\subseteq U.$ 
Suppose $w\in W:= \ker P$ so that $Pw=0.$ Then $P (Tw) = T(Pw) = T(0)=0$ so $Tw\in \ker P := W$ so $TW\subseteq W.$ 
It seems fine to me, but nowhere did I use that $P$ was a projection, I only used $TP=PT.$ Is my proof okay?

Yes, that's all. $P$ doesn't have to be projection for this particular exercise.
However, we can just start out from the fact that $P$ is a projection in a solution: now it projects to subspace $U$, in the direction of $W$, and we also have $U\oplus W=V$, and $P|_U={\rm id}_U$.
Having these, an operator $T$ commutes with $P$ iff both $U$ and $W$ are $T$-invariant subspaces. Your proof can be reformulated for one direction, and the other direction goes as:
If $TU\subseteq U$ and $TW\subseteq W$, then $TP(u+w)=Tu$, as it is $\in U$, it $=PTu$, and as $Tw\in W$, we finally have
$$TP(u+w)=Tu=PTu=PTu+PTw=PT(u+w)\,.$$
