The trick is that we know how to compute this integral exactly:
$$
\int e^{tx}dx
$$ The result is a function of $t$ (including the constant of integration)
$$
\int e^{tx} dx = \frac{1}{t}e^{tx} + C_1(t)
$$ So, this means (assuming everything is mathematically "kosher", which here it is),
$$
\frac{d}{dt}\int e^{tx}dx = \frac{d}{dt} \left(\frac{1}{t}e^{tx} + C\right) = -\frac{1}{t^2}e^{tx} + \frac{x}{t}e^{tx} + C_2(t)
$$ But on the other hand, (again, assuming we can "pull the derivative inside the integral", which we can here):
$$
\frac{d}{dt}\int e^{tx}dx = \int\frac{\partial}{\partial t}e^{tx} dx = \int xe^{tx}dx
$$ So we have arrived at the nice formula
$$
\int xe^{tx} dx = \left(\frac{x}{t} - \frac{1}{t^2}\right)e^{tx} + C_2(t)
$$ You can evaluate this at any value of $t$; $t=1$ will give $\int xe^xdx$. If you do this trick again (take a second derivative with respect to $t$) and evaluate the result at $t=1$, you can arrive at the formula for $\int x^2e^{x}dx$. Note that the "constant of integration" $C_1(t)$ can be chosen to be any function of $t$, so after evaluating at some $t$ value, we still have an "arbitrary constant" - if you were trying to evaluate a definite integral by this method, you could choose $C_1(t)\equiv 0$.