The error message is pretty clear:
The process cannot access the file 'D:\file.txt' because it is being used by another process
The file is open somewhere else, and when it was opened, it was given what's called an "exclusive lock" (this is normal for a file opened for writing to prevent two processes trying to change the same file and wrecking it for each other). Until the lock is removed (normally by closing the file) it cannot be opened by any process, even for reading.
Since you say you wrote the file using a binary writer, the most likely thing is that you didn't close the stream correctly and that code is causing the lock. Check your writer code and close and dispose all streams when you are finished with them.