What is the .data directory?

Title. Also, can I write to it programmatically?

Yes, you can write to it programatically. There was a short discussion about this yesterday:

It’s a directory where you can store persistent data. It isn’t copied when your project is remixed or exported to GitHub.