If it had bubbles on top before it was baked, then it will be foamy. What you can do to get rid of these bubbles is gently use a kitchen torch to blow away the bubbles before you bake your custard.