Suppose person a's consumption of good $y$ imposes a negative externality on person b. Person a's utility maximisation problem is $$\max_{x_a,y_a} \ u_a(x_a,y_a),$$ subject to $$p_x x_a+p_y y_a=e_a.$$ The first-order condition is $$\underbrace{\frac{\partial u_a}{\partial{y_a}}}_{\substack{\text{marginal} \\ \text{private} \\ \text{benefit}}}-\underbrace{\frac{p_y}{p_x}\frac{\partial u_a }{\partial x_a}}_{\substack{\text{marginal}\\ \text{private cost}}}=0.$$
The social welfare maximisation problem is $$\max_{x_a,\ y_a, \ x_b} \ u_a(x_a,y_a)+u_b(x_b,y_a),$$ subject to $$\begin{align*} p_xx_a+p_yy_a&=e_a,\\ p_xx_b&=e_b. \end{align*}$$ The first-order condition is $$\underbrace{\frac{\partial u_a}{\partial y_a}}_{\substack{\text{marginal} \\ \text{private} \\ \text{benefit}}}-\underbrace{ \underbrace{\frac{p_y}{p_x}\frac{\partial u_a }{\partial x_a}}_{\substack{\text{marginal} \\ \text{private cost}}}\ \ + \underbrace{\frac{\partial u_b}{\partial y_a}}_{\substack{\text{marginal} \\ \text{external} \\ \text{cost}}}}_{\text{marginal social cost}}=0,\\\\$$ where $\partial u_b/\partial y_a<0$.
An optimal Pigouvian tax should bring the competitive equilibrium to the social optimum. However, for some reason when I rewrite person a's budget constraint as $p_x x_a+(p_y+t) y_a=e_a$ and set $t$ equal to the marginal external cost, I do not get the first-order condition for the social optimum when I solve person a's utility maximisation problem again. What am I doing wrong?