You want two threads to write to the same file?
Then you have to use locking. That is each thread tries to get exclusive access to a shared resource (here a file) by using an appropriate function which enters a wait state until the resource is free and then locked. Then the resource can be used and is unlocked when done.
A possible solution for you (as far as I understand your code) would be making the
PrintDetails()
function thread safe. That is every critical section (here: checking for file existance and creating it if necessary, and writing to the file) must be guarded using locks (optionally as ReaderWriter lock), monitors, or mutexes. See
Thread Synchronization (C#) | Microsoft Docs[
^] for an introduction on this topic.