Let $(\Omega,\mathcal{F},\mathbb{P})$ be our probability space and let $\mathcal{G}\subset\mathcal{F}$ be a subalgebra. I consider only integrable r.v.'s for otherwise the conditional expectation is not defined. We have (see below):
$$E[XI_{G}]=E[YI_{G}]$$
for all $G\in\mathcal{G}$ (actually, it holds for any $G\in\mathcal{F}$).
Now, by definition of the conditional expectation, there exists a version $Z$ of $E[X\mid\mathcal{G}]$ and a version $Z'$ of $E[Y\mid\mathcal{G}]$ such that:
$$E[XI_{G}]=E[ZI_{G}]=E[YI_{G}]=E[Z'I_{G}]$$
for all $G\in\mathcal{G}$. This implies that $Z=Z'$ a.s. (in the sense that there exists a $\mathcal{G}$-measurable function $N$ such that $N=0$ a.s. and $Z=Z'+N$).
Note that if $V,W$ are two $\mathcal{A}$-measurable *integrable fonctions, we have $V=W$ a.s. if and only if $E[VI_{A}]=E[WI_{A}]$ for every $A$ in $\mathcal{A}$. One direction is easy. To see the "if" part, consider $A=\{V-W>0\}$ and $A=\{V-W<0\}$.