For some reason, I'd like to know the content of processor caches at arbitrary point of my C program. Is there anyway I can write contents in the cache to a file?
C doesn't know anything about your processor, its type, or its cache, or anything other related to that.
If you want to access this data, you would need OS-level functionality that supports it (which could potentially be callable from C). You need to look at your OS, and potential other choices, to find out if they support it.