In order to sell an asset during bankruptcy, you must file a petition for permission to sell the asset and the court and trustee must approve the sale. The proceeds from the sale are to be turned over to the trustee, then he/she will determine what portion of the money should go to the unsecured or secured creditors, how much your ex would get, etc. If you disagree with the trustee, you would bring the matter before the court for a decision.
If this didn't occur, and you sold property without leave of court, the trustee has a right to recover those funds. It may very well be that the money is divided how the court order requires, but you must run it through the trustee.
Also, the trustee is entitled to interest and penalties, but this usually can be negotiated and waived by the trustee.
If this was an honest mistake and you didn't try to defraud the court (which sounds like is what happened since you testified to the sale of this property - if you wanted to defraud the court, you would not have made a statement about the sale), you should be able to work something out. However, you need to try and cooperate with the trustee as he can make this as easy or as hard on you as he wants to.