I understand each transaction in the blockchain has a unique ID, is this generated when it is created or at the time it is written to the blockchain? Or is it generated by some other means?
The tx ID is basically a hash of the transaction data. So, in some sense, it is created as soon as you create the tx. At least when it is broadcasted to the network, the ID becomes known publicly. So not at mining time.
There's a small caveat, though: Due to a process called "transaction malleability", it is possible that someone (who need not be related to the tx in any way) can alter the tx in such a way that it is still valid, "means" the same thing but has a different ID. In that sense, you only know the (final) ID for sure once the tx is confirmed.