Define $ \bar{f}=\frac{\int_a^bf(t)\,g(t)\,\mathrm{d}t}{\int_a^bg(t)\,\mathrm{d}t}\tag{1} $ Then $ \int_a^b\left(f(t)-\bar{f}\right)\,g(t)\,\mathrm{d}t=0\tag{2} $ Suppose that $f(t_+)-\bar{f}\gt0$ and $f(t)-\bar{f}\ge0$ for all $t\in[a,b]$, then $f-\bar{f}$ is positive in some neighborhood of $t^+$ and therefore $\int_a^b\left(f(t)-\bar{f}\right)\,g(t)\,\mathrm{d}t\gt0$. Thus, there must be some $t_-$ where $f(t_-)-\bar{f}\lt0$.
Suppose that $f(t_-)-\bar{f}\lt0$ and $f(t)-\bar{f}\le0$ for all $t\in[a,b]$, then $f-\bar{f}$ is negative in some neighborhood of $t_-$ and therefore $\int_a^b\left(f(t)-\bar{f}\right)\,g(t)\,\mathrm{d}t\lt0$. Thus, there must be some $t_+$ where $f(t_+)-\bar{f}\gt0$.
Thus, if $f(t)-\bar{f}$ is not identically $0$ on $[a,b]$, we must have $t_+$ and $t_-$ where $f(t_+)-\bar{f}\gt0$ and $f(t_-)-\bar{f}\lt0$.
By the intermediate value theorem, there must be an $x$ between $t_+$ and $t_-$ such that $f(x)-\bar{f}=0$, which is the same as $ \int_a^bf(t)\,g(t)\,\mathrm{d}t=\bar{f}\int_a^bg(t)\,\mathrm{d}t=f(x)\int_a^bg(t)\,\mathrm{d}t\tag{3} $