@Manjot Bhathal The file system is read only by default. For file-based persistence, you should instead use the storage bindings which will store the file in blob storage, available to access across function invocations even as it scales out across instances.
An alternative you could explore is creating a Custom Connector for the Public APIs (if connectors don't exist already) and then leverage Logic Apps to run on a schedule, fetch data from the API A and then call API B.
Custom Connectors internally perform the same kind of token magic like you are trying to achieve and expects the required details when creating the custom connector. If this works out with the Public API, you could build your solution with almost no code to maintain.