The word “forthwith” means immediately, without delay. You’re right about it being used principally in formal written English, such as in legal documents. For example, when renting a flat in the UK, you will be asked to sign an agreement with the landlord. As part of the contract, you will promise to compensate the landlord for any damage to the flat when you move out. You will see words like “… the Tenant will reimburse the Landlord forthwith …”