Here we do not have a nested sum of nested series, since the scope of $k$ of the left-hand series does not affect the $k$ of the right-hand sum.
We obtain
\begin{align*}
\sum_{k=0}^\infty&\left(\sum_{n=0}^ka_n\right)x^k-\left(\sum_{n=0}^k x^{n}\right)a_k\\
&=\sum_{l=0}^\infty\left(\sum_{n=0}^la_n\right)x^l-a_k\left(\sum_{n=0}^k x^{n}\right)\tag{1}\\
&=\frac{1}{1-x}\sum_{l=0}^\infty a_lx^l-a_k\frac{1-x^{k+1}}{1-x}\tag{2}\\
&\,\,\color{blue}{=\frac{1}{1-x}\sum_{\substack{l=0\\l\ne k}}^\infty a_lx^l
+\frac{1}{1-x}a_k\left(x^k-1+x^{k+1}\right)}
\end{align*}
Comment:
In (1) we use the index $l$ for the left-hand series to better see the scope of it. Since $k$ on the right-hand side is a free variable we can factor out $a_k$.
In (2) we recall that multiplication of a generating function $A(x)$ with $\frac{1}{1-x}$ gives as coefficients the sum of the coefficients of $A(x)$ (Specific case of the Cauchy-product if one series is $\frac{1}{1-x}=1+x+x^2+\cdots$). We also use the finite geometric series expansion for the right-hand sum.
We have a different situation when we expand the scope of the left index $k$ by using parentheses to also enclose $k$ at the right-hand side. We then obtain
\begin{align*}
\sum_{k=0}^\infty&\left[\left(\sum_{n=0}^ka_n\right)x^k-\left(\sum_{n=0}^k x^{n}\right)a_k\right]\tag{3}\\
&=\left(\sum_{k=0}^\infty\sum_{n=0}^ka_n x^k\right)-\left(\sum_{k=0}^\infty a_k\sum_{n=0}^k x^{n}\right)\tag{4}\\
&=\frac{1}{1-x}\sum_{k=0}^\infty a_kx^k-\sum_{k=0}^\infty a_k\frac{1-x^{k+1}}{1-x}\\
&\,\,\color{blue}{=\frac{1}{1-x}\sum_{k=0}^\infty a_k\left(x^k-1+x^{k+1}\right)}
\end{align*}
Comment: