How to prevent small, young dog from going to the bathroom indoors?

Hello, Our 1 1/2 year old small dog randomly goes to the bathroom in the house. She pees and poop outdoors often (we have a dog door) but will randomly poop on our hardwood floors or pee on our small area rugs (we have no carpet thankfully!) There doesn't seem to be any rhyme or reason to it. She'll do great for a couple/few weeks then all of a sudden goes inside. Our older small dog always goes outdoors. It happens when we are both home & gone so its not a separation anxiety issue, we are home a lot. I know that punishing her after we find it ( later) doesn't help but we never seem to catch her in the act so. She is very food motivated and did well going outside as a puppy and responded well to treats. Any suggestions on how to break this habit at this point? We use enzyme cleaners to rid of the odor/stains so we don't think that is the problem. We are getting frustrated, its seems like we are going backwards Thank you!!