Perhaps, the following re-arrangement of the argument will help remove the mystery of the choice of $g(x,y)=\frac{\partial}{\partial x} \ln f(x,y)=\frac{f'_x(x,y)}{f(x,y)}$, where $f:=f_{X,Y}$ and ${}'_x$ denotes the partial derivative in $x$.
Assume appropriate regularity conditions, whatever are needed for the manipulations below. Integrating by parts, we have
\begin{equation}
\int x f'_x(x,y)\,dx=-\int f(x,y)\,dx,
\end{equation}
whence
\begin{equation}
EXg(X,Y)=\int\int x f'_x(x,y)\,dx\,dy=-1.
\end{equation}
Here, $\int:=\int_{-\infty}^\infty$.
Also, $\int f'_x(x,y)\,dx=0$ and hence
\begin{equation}
Eh(Y)g(X,Y)=\int dy\,h(y)\int f'_x(x,y)\,dx=0
\end{equation}
for any function $h$ (satisfying appropriate regularity conditions).
Therefore, $E(X-h(Y))g(X,Y)=-1$.
Thus, by the Cauchy-- Schwarz inequality (hardly possible to do without it),
\begin{equation}
E(X-h(Y))^2\ge\frac1{Eg(X,Y)^2}.
\end{equation}
Of course, here one can take $h(Y)=E(X|Y)$ (which actually minimizes the left-hand side of the last inequality).