I know that this has already been answered, but I was struggling with this myself, specifically in following Peskin's Argument where he drew an analogy with the quantum harmonic oscillator. I'm leaving this here in case anyone else has the same question we all did. $\def\k{\mathbf{k}} \def\phit{\tilde{\phi}} \def\d{\dagger} \def \x{\mathbf{x}}$
Peskin's Argument
Peskin begins by taking the fourier transform of the scalar field $\phi(\mathbf{x},t)$ as
$$
\phi(\mathbf{x},t) = \int \frac{d^3 \mathbf{k}}{(2\pi)^3} \tilde{\phi}(\mathbf{k},t) e^{i \mathbf{k} \cdot \mathbf{x}} \tag{1}
$$
Now, applying the Klein-Gordon equation to both sides we get an equation of motion for each Fourier mode $\phi(\mathbf{k},t)$
$$
(\Box^2 - m^2) \phi(\mathbf{x},t) = \int \frac{d^3 \mathbf{k}}{(2\pi)^3} \left( \partial_t^2 + m^2 + k^2 \right) \tilde{\phi}(\mathbf{k},t) =0
\\
\left( \partial_t^2 + \omega_\mathbf{k}^2 \right) \tilde{\phi}(\mathbf{k},t) = 0
\tag{2}
$$
Which is just the harmonic oscillator EOM with $\omega_\mathbf{k} = \sqrt{k^2 + m^2}$.From here Peskin argues that since $\tilde{\phi}(\mathbf{k},t)$ obeys the oscillator equation, we can promote each $\tilde{\phi}(\mathbf{k},t)$ to an operator using creation and annihilation operators in analogy with $X$ and $P$ in the Quantum Harmonic Oscillator:
$$
\phit(\k,t) = ``X" = \frac{1}{\sqrt{2\omega_\k}} (a_\k + a_\k^\d) \quad
\partial_t \phit(\k,t) = ``p" = -i \sqrt{\frac{\omega_\k}{2}}(a_\k - a_\k^\d)
\tag{3}
$$
Going into the Schrodinger Picture and plugging this into (1) we have
$$
\phi(\x) = \int \frac{d^3 \k}{(2\pi)^3} e^{-i \k \cdot \x}(a + a^\d)
\tag{4}
$$
This actually can't be correct, as we require $\phi(\x,t)$ to be Hermitian, and this is not. Peskin later writes down the correct expression as
$$
\phi(\x) = \int \frac{d^3 \k}{(2\pi)^3}(a e^{-i \k \cdot \x} + a^\d e^{-i \k \cdot \x})
\tag{5}
$$
But then, the question becomes, how does Peskin get here?
My Justification
Now, the justification for breaking down $\phit(\k,t)$ in terms of $a$ and $a^\d$ as has been written in (3) is the EOM obeyed by $\phit(\k,t)$, in (2) is the same as the one obeyed for the $X$ operator in the Quantum Harmonic Oscillator (QHO). As, for a regular QHO with Hamiltonian
$$
H = \omega(a^\d a + \frac{1}{2}) = \frac{1}{2}[P^2 + \omega^2 X^2] \tag{6}
$$
Then $X = \sqrt{\frac{1}{2\omega}}(a+a^\d)$ obeys the EOM $\partial_t^2 X = -\omega^2X$. But we should note that putting $\phit(\k)$ in analogy with $X$ is not exactly correct, as in this example $X$ is hermitian, and $\phit(\k)$ is not. The latter statement is easy to see by using the fact that $\phi(\x)$ is hermitian and writing down the inverse FT of $\phit(\k)$ as
$$
\phit(\k) = \int d^3\x e^{-i \k \cdot \x} \phi(\x) \\
\phit(\k)^\d = \int d^3\x e^{+i \k \cdot \x} \phi(\x) \neq \phit(\k)
\tag{7}
$$
It's not really valid to draw an analogy from a non-hermitian $\phit(\k)$ to a hermitian $X$ here. A natural next question to ask, would be: are there any non-hermitian operators we can construct in the QHO problem that still obey the same EOM?
The answer is, yes! Consider the following family of operators: $\def \xa{\bar{X}_\alpha} \def \pa{\bar{P}_\alpha} \def \palpha{e^{i\alpha}} \def \pnalpha{e^{-i\alpha}}$
$$
\xa = \sqrt{\frac{1}{2\omega}} (a + \palpha a^\d) \quad \pa = -i\sqrt{\frac{\omega}{2}}(a - \palpha a^\d) \tag{8}
$$
Where $a$ and $a^\d$ are still the usual QHO creation and annihilation operators present in the Hamiltonian in (6). Now, using the Heisenberg equation of motion ($dA/dt = -i[A,H]$)
$$
\dot{a} = -i \omega a \quad \dot{a}^\d = i \omega a^\d \tag{9}
$$
Plugging (9) into the definition of $\xa$ and $\pa$ we get two coupled differential equations for $\xa$ and $\pa$:
$$
\dot{\xa} = \sqrt{\frac{1}{2\omega}} (-i\omega)(a - \palpha a^\d) = \pa\\
\dot{\pa} = -i\sqrt{\frac{\omega}{2}} (-i\omega)(a+\palpha a^\d) = -\omega^2 \xa
\tag{10}
$$
Using the old trick of taking the derivative of the $\dot{\xa}$ equation and plugging in the $\dot{\pa}$ equation we decouple our equations. Then, as promised
$$
\ddot{\xa} = -\omega^2 \pa \tag{11}
$$
We recover the same equation of motion (2) for the non-hermitian operator $\xa$. Then, we can write the non-hermitian $\phit(\k)$ in terms of $a$ and $a^\d$ in the a more general way $\def \palphak {e^{i \alpha_\k}} \def \pnalphak {e^{-i \alpha_\k}}$
$$
\phit(\k) = \frac{1}{\sqrt{2\omega_k}} (a + \palphak a^\d) \tag{12}
$$
Where we have left $\alpha_\k$ to be an undetermined constant which we can choose to ensure hermiticity. If we substitute (12) all the way back into our initial expression for $\phi(\x,t)$
$$
\phi(\x) = \int \frac{d^3 \k}{(2\pi)^3} e^{i\k \cdot \x}(a + \palphak a^\d) =
\int \frac{d^3 \k}{(2\pi)^3} (e^{i\k \cdot \x}a + e^{i(\k \cdot \x+\alpha_\k)} a^\d)
\tag{13}
$$
In order to guarantee $\phi(\x)$ is hermitian we take the conjugate of (13) to solve for $\alpha_\k$.
$$
\phi(\x)^\d = \int \frac{d^3 \k}{(2\pi)^3} (e^{-i\k \cdot \x} a^\d + e^{-i(\k \cdot \x+\alpha_\k)} a)
\tag{14}
$$
Expanding the parenthesis in (13) and (14) and demanding the phases on $a$ and $a^\d$ be the same (as that way $\phi(\x)$ is hermitian). We have
$$
- \k \cdot \x = \k \cdot \x + \alpha_\k; \quad
\alpha_\k = -2 \k \cdot \x
$$
Then, putting $\alpha = \k \cdot \x$ into the expansion (13) we finally recover (5)
$$
\phi(\x) = \int \frac{d^3 \k}{(2\pi)^3} (e^{i\k \cdot \x}a + e^{-i\k \cdot \x} a^\d)
$$
Which was Peskin's confusing result.
So, the extra step that was glossed over in that particular section of Peskin is the requirement that $\phi$ be hermitian which we have explicitly demanded here using the fact that there are a family of non-hermitian operators we can construct that still obey the same EOM as $X$ in the QHO.