Case $\impliedby$:
Suppose $g \in \mathrm{span} (\mathrm{Id}, f, \dots, f^{n-1})$. That is $$g = a_0 \mathrm{Id} + a_i f + \cdots + a_{n-1} f^{n-1}$$ for constants $a_i$.
Then, for any $x \in E$,
\begin{align*}
(f \circ g)(x) &= f \left( a_0 \mathrm{Id}(x) + a_i f(x) + \cdots + a_{n-1} f^{n-1}(x) \right) \\
&= a_0 (f \circ \mathrm{Id})(x) + a_i (f \circ f)(x) + \cdots + a_{n-1} (f \circ f^{n-1})(x) \\
&= a_0 (\mathrm{Id} \circ f)(x) + a_i (f \circ f)(x) + \cdots + a_{n-1} (f^{n-1} \circ f)(x) \\
&= \left( (a_0 \mathrm{Id} + a_i f + \cdots + a_{n-1} f^{n-1}) \circ f \right)(x) \\
&= (g \circ f)(x) \text{.}
\end{align*}
Therefore, $f \circ g = g \circ f$.
(In short: turn $g$ into a linear combination of compositions of $f$, then use that a composition of $f$s can absorb a leading $f$ and emit a trailing $f$ (with the usual fact the identity commutes with everything).)
Case $\implies$: Suppose $g$ commutes with $f$ and let $e \in E$. We know $B = (e, f(e), \dots, f^{n-1}(e))$ is a basis of $E$, so it is sufficient to study $g$ on this basis. We find
\begin{align*}
g(e) &= \beta_0 \mathrm{Id}(e) + \beta_1 f(e) + \cdots + \beta_{n-1}f^{n-1}(e) \\
&\therefore \quad \left. g \right|_{\mathrm{span}\left( e \right)} \in \left. \mathrm{span} (\mathrm{Id}, f, \dots, f^{n-1}\;) \right|_{\mathrm{span}\left( e \right)} \text{,}
\end{align*}
for constants $\beta_i$. Then
\begin{align*}
(g \circ f)(e) &= (f \circ g)(e) \\
&= f(\beta_0 \mathrm{Id}(e) + \beta_1 f(e) + \cdots + \beta_{n-1}f^{n-1}(e)) \\
&= \beta_0 f(e) + \beta_1 f^2(e) + \cdots \beta_{n-1}f^{n-1}(e) + 0 \\
&\therefore \quad \left. g \right|_{\mathrm{span}\left( e, f(e) \right)} \in \left. \mathrm{span} (\mathrm{Id}, f, \dots, f^{n-1}\;) \right|_{\mathrm{span}\left( e \right)} \text{,} \\
(g \circ f^2)(e) &= (f^2 \circ g)(e) \\
&= \beta_0 f^2(e) + \beta_1 f^3(e) + \cdots + \beta_{n-1}f^{n-1}(e) + 0 + 0 \\
&\therefore \quad \left. g \right|_{\mathrm{span}\left( e, f(e), f^2(e) \right)} \in \left. \mathrm{span} (\mathrm{Id}, f, \dots, f^{n-1}\;) \right|_{\mathrm{span}\left( e \right)} \text{,} \\
&\vdots \\
(g \circ f^{n-1})(e) &= (f^{n-1} \circ g)(e) \\
&= \beta_0 f^{n-1}(e) + 0 + \cdots + 0 + 0 + 0 \\
&\therefore \quad \left. g \right|_{\mathrm{span}\left( e, f(e), f^2(e), \dots, f^{n-1}\;(e) \right)} \in \left. \mathrm{span} (\mathrm{Id}, f, \dots, f^{n-1}\;) \right|_{\mathrm{span}\left( e \right)} \text{.}
\end{align*}
So $g$ restricted to a basis of $E$ is in $\mathrm{span} (\mathrm{Id}, f, \dots, f^{n-1}\;)$; therefore, $g \in \mathrm{span} (\mathrm{Id}, f, \dots, f^{n-1})$.