Question: I was wondering how I could show that $\displaystyle \sum\_{x\leq Z}d(x)^2\ll Z(\log 2Z)^3$, where $d(x)$ counts the number of divisors of $x$. I tried to prove this in the following fashion (and failed spectacularly): 

Wlog assume $Z$ is an integer. Note that we have for a given $\epsilon>0$, there exists a constant $C$ depending on $\epsilon$ such that $|d(m)|\leq Cm^{\epsilon}$, i.e. $d(m)\ll m^{\epsilon}$. Summing, we have $\displaystyle \sum\_{x\leq Z}d(x)^2\leq 1+\dots+Z^{2\epsilon}\dots \boxed{1}$. Next, we consider the function $f(x)=x^{2\epsilon}$ and note that the sum in $\boxed{1}$ is less than or equal to $\displaystyle \int\_1^Zf(x)\mathrm{d}x=-\frac{1}{2\epsilon+1}+\frac{(Z+1)^{2\epsilon+1}}{2\epsilon+1}\leq \frac{(Z+1)^{2\epsilon+1}}{2\epsilon+1}\ll Z (Z+1)^{2\epsilon}$. This however doesn't seem to tell me how to proceed from here. Of course, taking $\epsilon$ to be $3/2$, we obtain $\displaystyle \sum\_{x\leq Z}d(x)^2\ll Z(Z+1)^3$ Thank you for any insights.

Answer: 
To show just the domination
$$\sum\_{n \leqslant Z} d(n)^2 \ll Z(\log Z)^3$$
(for $Z \geqslant 2$, so that I can use $\log Z$ instead of $\log (2Z)$) we can use a simple but non-obvious trick. For notational convenience and transparency I'll use the Iverson bracket
$$[P] = \begin{cases} 1 &\text{if } P, \\ 0 &\text{if } \lnot P. \end{cases}$$
The trick consists of writing
$$d(n) = \sum\_{k \mid n} 1 = \sum\_{k \leqslant Z} [k \mid n]$$
for $n \leqslant Z$ and then changing the order of summation:

\begin{align}
\sum\_{n \leqslant Z} d(n)^2
&= \sum\_{n \leqslant Z} d(n)\cdot \sum\_{k \leqslant Z} [k \mid n] \\
&= \sum\_{k \leqslant Z} \sum\_{n \leqslant Z} [k \mid n]\cdot d(n) \\
&= \sum\_{k \leqslant Z} \sum\_{m \leqslant Z/k} d(k\cdot m).
\end{align}
Next we use the complete submultiplicativity of the divisor counting function, $d(k\cdot m) \leqslant d(k)\cdot d(m)$ for all positive integers $k,m$. This is immediate from $1 + a + b \leqslant (1+a)(1+b) = 1 + a + b + ab$ for $a, b \geqslant 0$. Thus we obtain
\begin{align}
\sum\_{n \leqslant Z} d(n)^2
&= \sum\_{k \leqslant Z} \sum\_{m \leqslant Z/k} d(km) \\
&\leqslant \sum\_{k \leqslant Z} d(k)\sum\_{m \leqslant Z/k} d(m) \\
&\ll \sum\_{k \leqslant Z} d(k)\cdot \frac{Z}{k}\log \frac{Z}{k} \\
&\leqslant Z\log Z \sum\_{k \leqslant Z} \frac{d(k)}{k} \\
&\sim Z\log Z\cdot \frac{1}{2}(\log Z)^2 \\
&\ll Z(\log Z)^3.
\end{align}
Expanding Conrad's comment, Euler's product gives us
$$ \sum\_{n\geq 1}\frac{\tau(n)^2}{n^s}=\prod\_{p}\left(1+\frac{\tau(p)^2}{p^s}+\frac{\tau(p^2)^2}{p^{2s}}+\ldots\right)=\frac{\zeta(s)^4}{\zeta(2s)} $$
hence the abscissa of convergence of the Dirichlet series in the LHS is $1$. The RHS has a pole of order $4$ at $s=1$ and the "most singular" part is the same as $-\frac{1}{\pi^2}\zeta'''(s)$. By summation by parts

$$ \sum\_{n\geq 1}\frac{\tau(n)^2}{n^s} = \sum\_{N\geq 1}\left(\frac{1}{N^s}-\frac{1}{(N+1)^s}\right)\sum\_{n=1}^{N}\tau(n)^2=\sum\_{n\geq 1}\frac{s}{N^{s}}\cdot\frac{1}{N}\sum\_{n=1}^{N}\tau(n)^2+O\left(\sum\_{N\geq 1}\frac{s}{N^{s+2}}\sum\_{n=1}^{N}\tau(n)^2\right) $$
hence the average value $\frac{1}{N}\sum\_{n=1}^{N}\tau(n)^2$ behaves like $\frac{1}{\pi^2}\log^3(N)$, since
$$ -\frac{1}{\pi^2}\zeta'''(s) = \sum\_{N\geq 1}\frac{\frac{1}{\pi^2}\log^3 N}{N^s}.$$