I'm accustomed to IPFS as a store of data for the metadata of NFTs. But is it possible for a smart contract to write to ipfs? In my use case, I would like my NFT to pull its metadata, alter a few fields, push that new metadata to IPFS and lastly update its own token URI.
No, a smart contract cannot write to IPFS because Ethereum smart contracts cannot communicate with any off-chain resources directly, or else different nodes could receive different results every time a transaction is executed, and that would not be possible to achieve consensus in the Ethereum blockchain.
You may be able to use Chainlink for this. First use an Any API get request to fetch the metadata, then modify the metadata object accordingly inside your contract, then using a chainlink node setup with an external adapter to upload a JSON file to IPFS containing the new metadata object in your request. The chainlink node should be able to return the new CID which you can use to update your metadata URL. This is all pretty abstract, but should work!