He wants to get out of the investment fund but they stipulated that he must leave some money in it
Question

                I had some money that I put in the Post Office investment fund, and left it there for some time, then I realized that the profit that this money produces is nothing more than riba, so I went to withdraw the money and close the account, but the Post Office employee told me that I could not cancel it completely, and that I had to leave ten (Egyptian) pounds at least, even though the amount of interest that I collected was only twenty pounds. I withdrew the money and gave ten pounds of it to the mosque, and I regarded what was left in the account (ten pounds) as being the rest of the interest. Is what I did correct?.
Praise be to Allah.
    Firstly: 

    It is not permissible to subscribe to the investment fund 
    that gives a fixed percentage of the money deposited in it, because this is 
    riba which Allaah and His Messenger have forbidden. This is no different 
    from the riba-based banks except in name only, and you have done well to get 
    out of it. 

    It is well known that one who repents from riba is entitled 
    to his capital only, because Allaah says (interpretation of the meaning): “if 
    you repent, you shall have your capital sums. Deal not unjustly (by asking 
    more than your capital sums), and you shall not be dealt with unjustly (by 
    receiving less than your capital sums)” [al-Baqarah 2:279]. 

    The one who has taken riba-based interest has to get rid of 
    it by giving it to charitable causes. You have done that with half of the 
    interest when you gave it to the mosque. As for the other half which you 
    gave to the fund, it seems that this is also permissible, because this 
    wealth in fact belongs to the fund, since you took it by means of riba, but 
    riba is not a valid reason for you to take possession of the interest; you 
    are entitled to take nothing but the capital of your wealth only. 

    Secondly: 

    If the matter is as you describe, that the fund stipulated 
    that some of the money must be left in the account, then there is nothing 
    wrong with you leaving some money in the account, because you were compelled 
    to do that and did not do it by choice. But you have to understand that you 
    have no right to this money, because the money that you have left in it is 
    riba and does not belong to you. 

    So it is not permissible for you to ask the fund for any 
    money after today, rather you should consider yourself to have finished 
    dealing with it forever. 

    We ask Allaah to compensate you with something better. 

    And Allaah knows best.