Why does each mode of the electromagnetic field have two degrees of freedom?

This is a nice question, glossed over in many textbooks! Let's start with the electromagnetic field Hamiltonian, $$H \sim \frac12 \left(E^2 + B^2\right).$$ Naively one would say that $\mathbf{E}$ and $\mathbf{B}$ are the two degrees of freedom, giving the factor of two. But as you noted, this isn't correct. The fields $\mathbf{E}$ and $\mathbf{B}$ are not conjugate phase space variables, so the reasoning does not go through in analogy to the harmonic oscillator $$H \sim \frac12 \left(p^2 + \omega^2 x^2 \right).$$ Indeed $\mathbf{E}$ and $\mathbf{B}$ are instead proportional, as you noted. Another indication something is wrong is that there should be an $\omega^2$ in front of one of the terms.

A mode of the electromagnetic field really is analogous to a harmonic oscillator, but the argument requires more care. We note that $\mathbf{E}$ is the conjugate momentum to $\mathbf{A}$, and rewrite the Hamiltonian in terms of these variables. We use $\mathbf{B} = \nabla \times \mathbf{A}$ and work in Coulomb gauge $\nabla \cdot \mathbf{A} = 0$, which removes one of the polarizations. Dropping all constants, integrating by parts, and using $\omega^2 = k^2$, we find $$H \sim \frac12 (E^2 + \omega^2 A^2).$$ This is indeed a harmonic oscillator, giving the desired factor of $2$.