There exist programs (daemons) that can notify other programs (applications) when certain files change.
I don't have any experience with them, so I'm not sure if they can notify other programs
before the change occurs. I think that may not be possible.
But you could copy your test.txt before starting your program. Then have "fam" or "dnotify" notify another program when the files changes, and make a new copy of test.txt.
Some information on file-change notifying daemons ("fam" or "dnotify"):
http://www.devchannel.org/devtoolsch.../2146252.shtml
http://savannah.nongnu.org/projects/fam/
http://www.lambda-computing.com/projects/dnotify/
http://www.die.net/doc/linux/man/man1/dnotify.1.html