5. Given the ellipse $\frac{x^{2}}{a^{2}}+\frac{y^{2}}{b^{2}}=1(a>b>0)$ with left and right foci $F_{1}$ and $F_{2}$, respectively, and $P$ as any point on the ellipse not coinciding with the left or right vertices, points $I$ and $G$ are the incenter and centroid of $\triangle P F_{1} F_{2}$, respectively. When $I G$ is always perpendicular to the $x$-axis, the eccentricity of the ellipse is . $\qquad$
5. $\frac{1}{3}$.

Let $\left|P F_{1}\right|=n,\left|P F_{2}\right|=m$. Then $m+n=2 a$.
According to the properties of the orthocenter and incenter, we have
$$
\begin{array}{l}
\overrightarrow{P G}=\frac{1}{3}\left(\overrightarrow{P F_{1}}+\overrightarrow{P F_{2}}\right), \\
\overrightarrow{P I}=\frac{m \overrightarrow{P F_{1}}+n \overrightarrow{P F_{2}}}{m+n+2 c} \\
=\frac{1}{2} \cdot \frac{m \overrightarrow{P F_{1}}+n \overrightarrow{P F_{2}}}{a+c} . \\
\text { Therefore, } \overrightarrow{I G}=\frac{1}{6(a+c)}\left[(2 c+n-2 m) \overrightarrow{P F_{1}}+\right. \\
\text { and } \overrightarrow{P F_{1}} \cdot \overrightarrow{P F_{2}}=\frac{m^{2}+n^{2}-(2 c)^{2}}{2}, \text { thus, } \\
\overrightarrow{I G} \cdot \overrightarrow{F_{1} F_{2}}=\overrightarrow{I G} \cdot \overrightarrow{P F_{2}}-\overrightarrow{I G} \cdot \overrightarrow{P F_{1}} \\
=\frac{1}{6(a+c)}\left[(2 c+m-2 n) m^{2}-(2 c+n-2 m) n^{2}+\right. \\
\left.3(n-m) \frac{m^{2}+n^{2}-4 c^{2}}{2}\right] \\
=\frac{1}{3}(n-m)(a-3 c) .
\end{array}
$$

Since $I G \perp x$-axis, we know $\overrightarrow{I G} \cdot \overrightarrow{F_{1} F_{2}}=0$, substituting in we get $n=m$ (discard) or $a=3 c$.
Therefore, the eccentricity of the ellipse $e=\frac{c}{a}=\frac{1}{3}$.