It seems that ".*" also matches an empty string. So first "line1" will be replaced by "a" and then "" will also be replaced by "a" too giving "aa".
See
https://stackoverflow.com/questions/...-empty-strings
So try ".+" instead to avoid empty strings... I don't know why it works like that