I get a wrong determinant - why? I'm trying to calculate the following determinant:
$$\begin{vmatrix}
a_0 & a_1 & a_2 & \dots & a_n \\
a_0 & x & a_2 & \dots & a_n \\
a_0 & a_1 & x & \dots & a_n \\
\dots & \dots & \dots & \dots & \dots \\
a_0 & a_1 & a_2 & \dots & x
\end{vmatrix} = $$ $$ = \begin{vmatrix}
a_0 & a_1 & a_2 & \dots & a_n \\
a_0 & a_1 & a_2 & \dots & a_n \\
a_0 & a_1 & a_2 & \dots & a_n \\
\dots & \dots & \dots & \dots & \dots \\
a_0 & a_1 & a_2 & \dots & a_n
\end{vmatrix} + \begin{vmatrix}
0 & 0 & 0 & \dots & 0 \\
0 & x - a_1 & 0 & \dots & 0 \\
0 & 0 & x - a_2 & \dots & 0 \\
\dots & \dots & \dots & \dots & \dots \\
0 & 0 & 0 & \dots & x-a_n
\end{vmatrix} = 0 + 0 = 0 $$
Still, experimental results contradict, since for one example I get a non-zero determinant.
What am I doing wrong?

Determinant is a multilinear map so the linearity works in a different way. Operation that you made corresponds to linearity in a sense
$\det(A+B) = \det(A) + \det(B)$. This is true in general only for 1x1 matrices. The correct way to use the linearity of determinant is
$$
\det(x_1 + \alpha y_1,x_2,\cdots,x_n) = \det(x_1,x_2,\cdots,x_n) + \alpha \det(y_1,x_2,\cdots,x_n)
$$
where $x_1,\cdots,x_n,y_1$ are vectors of rows/columns of the matrix. So in your case the correct manipulation is
$$
\begin{vmatrix}
a_0 & a_1 & a_2 & \dots & a_n \\
a_0 & x & a_2 & \dots & a_n \\
a_0 & a_1 & x & \dots & a_n \\
\dots & \dots & \dots & \dots & \dots \\
a_0 & a_1 & a_2 & \dots & x
\end{vmatrix} = \begin{vmatrix}
a_0 & a_1 & a_2 & \dots & a_n \\
a_0 & x - a_1 + a_1 & a_2 & \dots & a_n \\
a_0 & a_1 & x & \dots & a_n \\
\dots & \dots & \dots & \dots & \dots \\
a_0 & a_1 & a_2 & \dots & x
\end{vmatrix} =
\begin{vmatrix}
a_0 & 0 & a_2 & \dots & a_n \\
a_0 & x - a_1 & a_2 & \dots & a_n \\
a_0 & 0 & x & \dots & a_n \\
\dots & \dots & \dots & \dots & \dots \\
a_0 & 0 & a_2 & \dots & x
\end{vmatrix} +
\begin{vmatrix}
a_0 & a_1 & a_2 & \dots & a_n \\
a_0 & a_1 & a_2 & \dots & a_n \\
a_0 & a_1 & x & \dots & a_n \\
\dots & \dots & \dots & \dots & \dots \\
a_0 & a_1 & a_2 & \dots & x
\end{vmatrix}
$$
