For the linear equation y'+ f(x)y= g(x), and integrating factor is a function m(x) such that multiplying by it, m(x)y'+ m(x)f(x)y= f(x)g(x), reduces the left side to a single derivative: (m(x)y)'. Since, by the product rule, (m(x)y)'= my'+ m'y= my'+ mfy, we must have m'= m(x)f(x) which is, itself, a separable differential equation: dm/m= f(x)dx so [itex]ln(m)= \int f(x)dx[/itex] and so [itex]m(x)= e^{\int f(x)dx}[/itex]. For this particular problem f(x) is the constant -1 so your integrating factor is [itex]e^{-x}[/itex], not [itex]e^x[/itex]. Multiplying the equation by [itex]e^{-x}[/itex], we have [itex]e^{-x}y'- e^{-x}y= (e^{-x}y)'= xe^{-x}[/itex]. Integrating both sides of that (the left side by parts, as loop quantum gravity said) you get [itex]e^{-x}y= -(x+1)e^{-x}+ C[/itex] or [itex]y= -x- 1+ Ce^x[/itex] and, since y(0)= 2, 2= -1+ C and C= 3.
[itex]y= -x-1+ 3e^x[/itex]
Notice that if [itex]y= x- 1+ 3e^{-x}[/itex] then [itex]y'= 1- 3e^{-x}[/itex] while [itex]y+ x= x- 1+ 3e^{-x}+ x= 2x- 1+ 3e^{-x}[/itex] so your y does NOT satisfy the differential equation.