When I make ghee I always skim the foam as taught to me by a friend from India. I was never given an explanation of why but if I leave the foam cook back into the ghee, it becomes grainy. Each time I make it, I always skim the foam and use it in stir fry the same day. No waste. If I leave the foam in the pan of ghee while it cooks down, my ghee is always grainy. It doesn't effect the flavor, but the texture is different.
I use ghee quickly, leave it covered on the counter, and never have had it spoil. If it gets moldy in or out of the fridge if you don't use it fast (like several weeks), then all of the moisture has not been cooked out of it while making it.
The sounds you hear when it is cooking is the water content cooking out. When it stops making those sounds and the bottom begins to brown, it is done. You have to watch it if your stove is hot or it will burn quickly once it reaches a certain temperature. Like making popcorn, you take it off of the heat BEFORE it completely stops popping so it doesn't burn. Therefore, once it begins to brown and it makes no more sound, it is done. If you go beyond this, it will burn. For this reason, I make ghee on a medium heat with organic, grass fed, unsalted butter only. It takes roughly 1/2 hour to 45 minutes. Some prefer to make it fast, like 20 minutes, but you really have to be vigilant and not leave the kitchen while it is cooking.
Strain and store in a sterile glass jar after it has cooled down a bit. Don't forget to sterilize the lid as well. You can strain the completed ghee while it is warm, not hot, through a fine strainer or cheesecloth into a glass jar, not plastic.
NB: Ghee is great used in bullet-proof coffee. I use one teaspoon ghee, one teaspoon coconut oil, and one teaspoon cocoa powder (unsweetened) per cup of brewed coffee. Use an immersion blender to blend in a tall sided bowl until frothy and you will be amazed at how the 4 flavors blend. They blend into a sumptuous flavor where you can not pick out either of the oils or the cocoa. Some recipes on line call for more oils, but this is my happy medium. Experiment with quantities of oils, up to one full tablespoon of each oil with or without cocoa. It will be the only coffee you will need during the day, unless you are a caffeine junky.