Does reciting tashahud twice invalidates the prayer? For example I recited it in second rakat then when I stood up for 3rd rakat I had doubt so I recited it again?

The answer is very simple that is after completion of namaz you should two “sajdah e Sahw” and then recite salam and Tashahhud and finish your namaz.

But let me tell you detailed answer:

There are 11 things wajib in the prayers:
1. Niyyah: Intention to pray for being near to God.
2. Takbirat-ul-Ihram (Allahu Akbar after niyyah).
3. Qiyam: To stand.
4. Ruku’.
5. Two Sajdahs.
6. Qira'at: to recite Surah al-Hamd and another Surah in first two rak’ats and Tasbihat al-Arba’ah.
(Subhanallahi wal-hamdu lillahi wa la ilaha illal-lahu wallahu Akbar) or Surah al-Hamd in
the 3rd and 4th rak’ats.
7. Dhikr: to recite tasbih in ruku’ and sajdah, as will be explained later.
8. Tashahhud.
9. Salaam.
10. Tartib: To pray in the sequence prescribed by the shari’ah.
11. Muwalaat: To pray without interruption or gap.

Rukn and Ghayr Rukn
Out of the above mentioned wajib acts of prayer, 5 are rukn and the others are ghayr rukn.
Rukn means such actions which invalidate the prayer if they are left out or added, though unintentionally.
These are (1) Niyyah, (2) Takbiratul-Ihram (3) Qiyam at the time of Takbiratul-Ihram and just before going to Ruku, (4) Ruku and (5) Both sajdahs together. If any of these are left out, or added whether intentionally or unintentionally, the Salat will become batil (void).
Ghayr rukn means such wajib acts which invalidate the prayer if they are left out, or added, intentionally. But they do not invalidate the prayer if they are left or added unintentionally. These are the remaining wajib acts of prayer.

Tashahhud is one of the Ghayr Rukn therefore your namaz will not become invalid if you omit it or recite it twice unintentionally because so as per rule in four places a person has to perform Sahja e Sahv:

1-one forgets to say Tashahhud.
2-one generally knows that he has mistakenly omitted or added something in a prayer.
3-one inadvertently talks during prayers;
4-one says the salām of the prayer at a time when he must not to say.
The method of performing sajdatā al-sahw:
Immediately after the salām of the prayer, one must make the intention of sajdatā al-sahw and place his forehead, based on obligatory precaution, on something on which performing sajdah is permitted. The recommended precaution is that one should say dhikr in the sajdah, and it is better that he says:
‎بِسْمِ اللهِ وَ بِاللهِ، اَلسَّلَامُ عَلَیْكَ أَيُّـهَا النَّبِيُّ وَ رَحْمَةُ اللهِ وَ بَـرَکَاتُهُ
Then, he must sit up and go into sajdah again, and he should say the dhikr mentioned above. [He must then sit] and say tashahhud,after which he must say:
‎اَلسَّلَامُ عَلَیْكُمْ
‎وَ رَحْمَةُ اللهِ وَ بَـرَکَاتُهُ