The Jambos conceded to Liam Fox five minutes into the second half before Jamie Hamill’s 61st minute penalty levelled it at Stark’s Park which eventually saw the game into extra-time and subsequently to a penalty shootout.
Hearts managed to edge their Championship opponents 5-4 in the shootout and Locke was content with progressing to the third round despite the scare.
"It was certainly not what we wanted, with it going to extra-time,” said Locke.
"We did not do too well in the first half but the second half was a lot better. They got everyone behind the ball when they went down to 10 men (after Dougie Hill’s sending off in the 74th minute).
"We're delighted to be through, the boys' character was fantastic."