The second equality is the typical trick of adding/subtracting things until you get something you want. It is usually not terribly insightful but is nonetheless standard. In general, one can factor $a^n-b^n$ as $$ a^n-b^n = (a-b)(a^{n-1} + a^{n-2}b^1 + a^{n-3}b^2 + \cdots + a^2 b^{n-3} + a b^{n-2} + b^{n-1}).$$ One way of seeing this more general result is as follows: Consider the polynomial equation $x^3-b^3$ (where I have just used $x$ instead of $a$!). Clearly $x=b$ is a root of this equation, so we should be able to factor out an $(x-b)$ term from the polynomial. Polynomial long division then gives the desired result. This can be generalized to higher $n$.